package com.zhengjiang.nacos.consumer.service;

import com.zhengjiang.nacos.consumer.feign.OrderServiceClient;
import com.zhengjiang.nacos.consumer.feign.StorageServiceClient;
import com.zhengjiang.nacos.consumer.model.Order;
import com.zhengjiang.nacos.consumer.model.Storage;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("productOrderService")
public class ProductOrderServiceImpl implements ProductOrderService {

    @Autowired
    OrderServiceClient orderServiceClient;
    @Autowired
    StorageServiceClient storageServiceClient;

    @GlobalTransactional(rollbackFor = Exception.class)
    @Override
    public String submitProductOrder(Order order) {
        orderServiceClient.submitOrder(order);
        Storage storage = new Storage();
        storage.setCommodityCode(order.getCommodityCode());
        storage.setCount(order.getCount());
        storageServiceClient.decryStorage(storage);
//        System.out.println(1/0);
        return null;
    }
}
